package com.springboot.frame.oauth.server.security.hadler;

import com.springboot.frame.oauth.server.utils.ResponseUtils;
import com.springboot.frame.oauth.server.utils.RestResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AuthenticationSuccessHandler;
import org.springframework.stereotype.Component;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * security 登录成功的实现
 */
@Component
@Slf4j
public class SecurityAuthenticationSuccessHandler implements AuthenticationSuccessHandler {

    @Override
    public void onAuthenticationSuccess(HttpServletRequest request,
                                        HttpServletResponse response,
                                        Authentication authentication) throws ServletException, IOException {
        // JSON 格式的返回
        ResponseUtils.renderSuccessJson(request, response, new RestResult(200, "登录成功"));
    }
}

